<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:csharp="http://csharp.org"
  xsi:schemaLocation='urn:oasis:names:tc:emergency:EDXL:HAVE:1.0 edxl-have_pr3.xsd'
  xmlns:cap = 'urn:oasis:names:tc:emergency:cap:1.2'
  xmlns:have='urn:oasis:names:tc:emergency:EDXL:HAVE:1.0'
  xmlns:de='urn:oasis:names:tc:emergency:EDXL:DE:1.0'
  xmlns:n3='http://www.georss.org/georss'
  xmlns:gml='http://www.opengis.net/gml'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:xal='urn:oasis:names:tc:ciq:xal:3'
  xmlns:xnl='urn:oasis:names:tc:ciq:xnl:3'
  xmlns:xpil='urn:oasis:names:tc:ciq:xpil:3'
		>

  <xsl:import href="Area Scripts.xsl"/>

  <xsl:output method="html" indent="yes" exclude-result-prefixes="msxsl csharp"/>



  <msxsl:script language="CSharp" implements-prefix="csharp">
    <![CDATA[

	public string getColoredStatus(string input)
	{
    if(input=="true" || input=="True" || input=="1"){
      return "<b><div class='GreenStatus'>Available</div></b>";
    }
    else if(input=="false"||input=="False"||input=="0"){
      return "<b><div class='RedStatus'>Not Available</div></b>";
    }
    else{
      return "--";
    }
	}
	]]>
  </msxsl:script>
  


  <xsl:template match="*">

    <HTML>
      <HEAD>

        <STYLE TYPE="text/css">
          .contentDesc
          {
          padding-left: 25pt;
          padding-right: 50pt;
          }

          .indented
          {
          padding-left: 50pt;
          padding-right: 50pt;
          }

          .indented2
          {
          padding-left: 75pt;
          padding-right: 50pt;
          }

          .indented3
          {
          padding-left: 100pt;
          padding-right: 50pt;
          }

          .indented4
          {
          padding-left: 125pt;
          padding-right: 50pt;
          }

          .GreenStatus
          {
          color:green;
          }

          .RedStatus
          {
          color:red;
          }
        </STYLE>




        <style type="text/css">
          #map-canvas {
          height: 500px;
          }
        </style>

        <script type="text/javascript">
          <xsl:attribute name="src">http://www.google.com/jsapi?autoload={'modules':[{name:'maps',version:3,other_params:'sensor=false'}]}</xsl:attribute>
        </script>

        <script type="text/javascript">


          //http://code.google.com/apis/maps/articles/mvcfun.html
          /**
          * A radius widget that add a circle to a map and centers on a marker.
          *
          * @constructor
          */
          function RadiusWidget(map) {
          this.set('map', map);
          this.set('position', map.getCenter());


          var circle = new google.maps.Circle({
          strokeWeight: 2});

          // Bind the radiusWidget map to the DistanceWidget map
          //this.bindTo('map', this);

          // Bind the radiusWidget center to the DistanceWidget position
          //radiusWidget.bindTo('center', this, 'position');


          // Set the distance property value, default to 50km.
          this.set('distance', 50);

          // Bind the RadiusWidget bounds property to the circle bounds property.
          this.bindTo('bounds', circle);

          // Bind the circle center to the RadiusWidget center property
          circle.bindTo('center', this);

          // Bind the circle map to the RadiusWidget map
          circle.bindTo('map', this);

          // Bind the circle radius property to the RadiusWidget radius property
          circle.bindTo('radius', this);
          }
          RadiusWidget.prototype = new google.maps.MVCObject();


          /**
          * Update the radius when the distance has changed.
          */
          RadiusWidget.prototype.distance_changed = function() {
          this.set('radius', this.get('distance') * 1000);
          };

          function init() {
          var mapDiv = document.getElementById('map-canvas');
          var map = new google.maps.Map(mapDiv, {
          center: new google.maps.LatLng(37.790234970864, -122.39031314844),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
          });

          // Create a new radius widget
          var radiusWidget = new RadiusWidget(map);
          }

          //google.maps.event.addDomListener(window, 'load', init);




        </script>





        <script type="text/javascript">
          <xsl:value-of select="document('CommonJavascript.js')" disable-output-escaping="yes" />
        </script>

        <TITLE>HAVE Message</TITLE>
        <link rel="stylesheet" media="screen" type="text/css" href="css/style.css" />
      </HEAD>




      <BODY>

        <!--Comment -->





        <xsl:for-each select="//have:Hospital">
          <xsl:variable name="NameElement">
            <xsl:value-of select="have:Organization/have:OrganizationInformation/xnl:OrganisationName/xnl:NameElement"/>
          </xsl:variable>

          <TABLE bordercolor="#ababab" border="1px" cellpadding="0" cellspacing="0" width="1200">
            <xsl:for-each select="have:Organization/have:OrganizationInformation">
              <TR>
                <TD align = "center" colspan="4" bgcolor="#F2F2F2">
                  <B>
                    <U>
                      <a>
                        <xsl:attribute name="href">
                          http://maps.google.com/maps?q=<xsl:value-of select="xnl:OrganisationName/xnl:NameElement"/>
                        </xsl:attribute>
                        <xsl:value-of select="xnl:OrganisationName/xnl:NameElement"/>
                      </a>
                    </U>
                  </B><BR/>
                  <xsl:value-of select="xpil:Addresses/xpil:Address/xal:FreeTextAddress/xal:AddressLine"/><BR />
                  <xsl:value-of select="xpil:Addresses/xpil:Address/xal:PostCode/xal:Identifier"/><BR /><br/>
                  Administrative Area: <xsl:value-of select="xpil:Addresses/xpil:Address/xal:AdministrativeArea/xal:NameElement"/><br/>
                  Sub Administrative Area: <xsl:value-of select="xpil:Addresses/xpil:Address/xal:AdministrativeArea/xal:SubAdministrativeArea/xal:NameElement"/><br/>
                  <a>
                    <xsl:attribute name="href">
                      http://maps.google.com/maps?q=<xsl:value-of select="../have:OrganizationGeoLocation/gml:Point/gml:pos"/>
                    </xsl:attribute>
                    <xsl:value-of select="../have:OrganizationGeoLocation/gml:Point/gml:pos"/>
                    <BR />
                  </a>
                </TD>
              </TR>
              <TR>
                <TD align="left" colspan = "2" height="40" valign="middle" width="50%">
                  <script type="text/javascript">

                    document.write("<b>Last Updated: </b>"+TimeStampToDate("<xsl:value-of select="../../have:LastUpdateTime"/>")+"<br/>");

                    var sentDate = TimeStampToDate("<xsl:value-of select="../../have:LastUpdateTime"/>");
                    var today=new Date();

                    //Get 1 hour in milliseconds
                    var one_hour=1000*60*60;

                    //Get 1 minute in milliseconds
                    var one_minute=1000*60;

                    <![CDATA[
															if(today.getTime()-sentDate.getTime() < 0 ){
																document.write("<b>(in the future)</b><br/>");
															}
															else if(today.getTime()-sentDate.getTime() < one_minute ){
																document.write("<b>(right now)</b><br/>");
															}
															
															]]>
                    else{




                    //Calculate difference btw the two dates, and convert to hours ... Update: And Minutes, with grammar

                    var hours = Math.floor((today.getTime()-sentDate.getTime())/(one_hour));
                    var minutes = Math.floor( (today.getTime()-sentDate.getTime())/(one_minute) - (hours*60)  );

                    var minutes_string;
                    if(minutes != 1){
                    minutes_string = minutes + " minutes ";
                    }
                    else{
                    minutes_string = minutes + " minute ";
                    }

                    var hours_string;
                    if(hours != 1){
                    hours_string = hours + " hours ";
                    }
                    else{
                    hours_string = hours + " hour";
                    }
                    document.write("<b>("+hours_string+" and "+minutes_string+" ago )</b><br/>");
                    }


                  </script>
                </TD>
                <TD align="left" colspan = "2" height="40" valign="middle" width="50%">
                  <B>
                    <U>Contact: </U>
                  </B> -
                  <xsl:for-each select="xpil:ContactNumbers/xpil:ContactNumber">
                    <xsl:value-of select='xpil:ContactNumberElement'/>
                  </xsl:for-each>
                  <BR/>
                </TD>
              </TR>
            </xsl:for-each>
            <TR>
              <TD align="center" colspan="2" valign="top">
                <B>
                  <U>EMS Traffic Status</U>
                </B>
                <BR/>
                <BR/>
                <xsl:value-of select="have:EMSTrafficStatus"/>
              </TD>
              <TD align="center" colspan="2">
                <B>
                  <U>Triage Codes</U>
                </B>
                <TABLE width="100">

                  <xsl:for-each select="have:TriageCode">
                    <TR>
                      <TD>
                        <B>
                          <font>
                            <xsl:attribute name="color">
                              <xsl:value-of select="have:TriageCodeValue"/>
                            </xsl:attribute> *
                          </font>
                          <xsl:value-of select="have:TriageCodeValue" />
                        </B>
                      </TD>
                      <TD>
                        <xsl:value-of select="have:TriageCountQuantity" />
                      </TD>
                    </TR>
                  </xsl:for-each>

                </TABLE>
              </TD>
            </TR>
            <TR>
              <TD align="center" colspan="4" >
                <B>
                  <I>Bed Capacity Status</I>
                </B>
                <BR/>
              </TD>
            </TR>
            <TR>
              <TD colspan="4">
                <TABLE width="100%" align="center" border="1">
                  <TR>
                    <xsl:for-each select="have:HospitalBedCapacityStatus">
                      <xsl:for-each select="have:BedCapacity">
                        <TD align="center" width="33%">
                          <B>
                            <I>
                              <xsl:value-of select="have:BedType" />
                            </I>
                          </B>
                          <HR/>
                          Available: <xsl:value-of select="have:Capacity/have:AvailableCount" /><BR/>
                          BaseLine: <xsl:value-of select="have:Capacity/have:BaselineCount" /><BR/>
                          <BR/>
                        </TD>
                      </xsl:for-each>
                    </xsl:for-each>
                  </TR>
                </TABLE>
              </TD>
            </TR>
            <TR>
              <TD align="center" colspan="4">
                <B>
                  <I>Hospital Information</I>
                </B>
                <BR/>
              </TD>
            </TR>
            <TR>
              <TD colspan="4">
                <TABLE width="100%" border="1" align="center">
                  <TR>
                    <TD align="left" valign="top" width="30%">

                      <B>
                        <I>
                          <U>Service Coverage Status</U>
                        </I>
                      </B>
                      <BR/>

                      <TABLE width="100%" border="0">

                        <xsl:for-each select="have:ServiceCoverageStatus">
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Burn:</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Burn)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Cardiology</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:CardiologyIndicator/have:Cardiology)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Dialysis</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Dialysis)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Emergency Department</B>
                            </TD>
                            <TD>
                              <xsl:variable name="EmergencyDepartmentStatus">
                                <xsl:value-of select="have:EmergencyDepartment" />
                              </xsl:variable>

                              <!-- todo: dmcgarry specified this, is it correct? -->
                              <xsl:choose>
                                <xsl:when test="contains($EmergencyDepartmentStatus, 'true')">
                                  Diversion
                                </xsl:when>
                                <xsl:when test="contains($EmergencyDepartmentStatus, 'false')">
                                  Open
                                </xsl:when>
                                <xsl:otherwise>
                                  --
                                </xsl:otherwise>
                              </xsl:choose>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Hyperbaric Chamber</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:HyperbaricChamber)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Infectious Disease</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:InfectiousDisease)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Neonatology</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Neonatology)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Neurology</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:NeurologyIndicator/have:Neurology)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>OBGYN</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:OBGYNIndicator/have:OBGYN)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Ophthalmology</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Ophthalmology)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Orthopedic</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Orthopedic)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Pediatrics</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Pediatrics)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Psychiatric</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:PsychiatricIndicator/have:Psychiatric)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>
                                  <I>Surgery</I>
                              </B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:SurgeryIndicator/have:Surgery)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          
                          
                         <!-- todo: make this part supported in the EDXL Sharp lib, then add support here
                          <TR>
                           
                            <TD>  *  Adult General Sugery</TD>
                            <TD>
                              <xsl:value-of select="have:SurgeryIndicator/have:SurgerySubType/have:AdultGeneralSugery" />
                              <xsl:value-of select="csharp:getColoredStatus(have:SurgeryIndicator/have:SurgerySubType/have:AdultGeneralSugery)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD>  *  Cardio Thoracic</TD>
                            <TD>
                              <xsl:value-of select="have:SurgeryIndicator/have:SurgerySubType/have:CardioThoracic" />
                            </TD>
                          </TR>
                          -->
                          
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Transport Services</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:TransportServicesIndicator/have:TransportServices)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Trauma Center Services</B> - <xsl:value-of select="have:TraumaCenterServicesIndicator/have:TraumaCenterServicesLevel" />
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:TraumaCenterServicesIndicator/have:TraumaCenterServices)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                        </xsl:for-each>
                      </TABLE>

                      <br/>
                      <B>
                        <I>
                          <U>Additional Status</U>
                        </I>
                      </B>
                      <BR/>
                      <TABLE width="100%" border="0">
                        <xsl:for-each select="have:ServiceCoverageStatus/have:AdditionalStatus/have:Service">
                          <TR>
                            <TD align="left">
                              <B>
                                <xsl:value-of select="have:Name" />:
                              </B>
                            </TD>
                            <TD>
                              <xsl:value-of select="csharp:getColoredStatus(have:Status)" disable-output-escaping="yes"/>
                            </TD>
                          </TR>
                        </xsl:for-each>
                      </TABLE>

                    </TD>
                    <TD align="left" valign="top" width="25%">
                      <TABLE width="100%" border="0">
                        <tr>
                          <td>
                            <B>
                              <I>
                                <U>Facility Status</U>
                              </I>
                            </B>
                            <BR/>
                          </td>
                        </tr>
                        <xsl:for-each select="have:HospitalFacilityStatus">
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Clinical Status:</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:ClinicalStatus" />
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Facility Status: </B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:FacilityStatus" />
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Security Status: </B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:SecurityStatus" />
                            </TD>
                          </TR>
                        </xsl:for-each>

                        <tr>
                          <td>
                            <B>
                              <I>
                                <U>
                                  <br/><BR/>Comments
                                </U>
                              </I>
                            </B>
                            <BR/>
                          </td>
                        </tr>
                        <xsl:for-each select="have:HospitalFacilityStatus/have:CommentText">
                          <TR>
                            <TD>
                              <xsl:value-of select="." />
                            </TD>
                          </TR>
                        </xsl:for-each>

                        <tr>
                          <td>
                            <B>
                              <I>
                                <U>
                                  <br/><BR/>Additional Facility Status
                                </U>
                              </I>
                            </B>
                            <BR/>
                          </td>
                        </tr>
                        <xsl:for-each select="have:HospitalFacilityStatus/have:AdditionalStatus/have:Service">
                          <TR>
                            <TD>
                              <b>
                                <xsl:value-of select="have:Name" />:
                              </b>
                              <xsl:value-of select="have:Status" />
                            </TD>
                          </TR>
                        </xsl:for-each>
                      </TABLE>
                    </TD>
                    <TD align="left" valign="top" width="25%">
                      <TABLE width="100%" border="0">
                        <B>
                          <I>
                            <U>Resource Status</U>
                          </I>
                        </B>
                        <BR/>
                        <xsl:for-each select="have:HospitalResourceStatus">
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Staffing:</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:Staffing" />
                            </TD>
                          </TR>
                          <TR>
                            <TD align="left">
                              <B>Facility Operations</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:FacilityOperations" />
                            </TD>
                          </TR>
                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Clinical Operations</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:ClinicalOperations" />
                            </TD>
                          </TR>
                          <TR>
                            <TD colspan="2">
                              <HR/>
                              <xsl:for-each select="have:ResourcesInformationText">
                                <xsl:value-of select="." />
                                <BR/>
                                <BR/>
                              </xsl:for-each>
                            </TD>
                          </TR>
                        </xsl:for-each>
                      </TABLE>
                    </TD>

                    <TD align="left" valign="top" width="25%">
                      <TABLE width="100%" border="0">
                        <B>
                          <I>
                            <U>Emergency Department Status</U>
                          </I>
                        </B>
                        <BR/>
                        <xsl:for-each select="have:EmergencyDepartmentStatus">

                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>EMS Traffic:</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:EMSTraffic/have:EMSTrafficStatus" />
                            </TD>
                          </TR>

                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Comment:</B>
                            </TD>
                            <TD>
                              <xsl:value-of select="have:CommentText" />
                            </TD>
                          </TR>

                          <TR>
                            <xsl:attribute name="bgcolor">#F2F2F2</xsl:attribute>
                            <TD align="left">
                              <B>Addtional Status:</B>
                            </TD>

                            <TD colspan="2">
                              <xsl:for-each select="have:AdditionalStatus/have:Service">

                                <xsl:value-of select="have:Name" /> = <xsl:value-of select="have:Status" /><br/>

                              </xsl:for-each>
                            </TD>

                          </TR>
                        </xsl:for-each>

                      </TABLE>
                    </TD>
                  </TR>
                </TABLE>
              </TD>
            </TR>
          </TABLE>
          <BR />
          <BR />
        </xsl:for-each>







      </BODY>
    </HTML>
  </xsl:template>
</xsl:stylesheet>